package eu.codlab.game.gameba.activities;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;

public class GameBoidConsoleActivity extends Activity{
	private static GameBoidManager manager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(manager == null){
			manager = GameBoidManager.getInstance(this, false);
		//	Log.d("manager","oncrecreate");
		}
		manager.setActivity(this);
		manager.onCreate(savedInstanceState);
		Log.d("manager","oncreate 2");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();

		if(manager != null)
			manager.onDestroy();
		manager = null;
		Log.d("manager","ondestroy");
	}

	@Override
	protected void onPause() {
		super.onPause();
		if(manager != null)
			manager.onPause();
		Log.d("manager","onpause");
	}

	@Override
	protected void onResume() {
		super.onResume();
		if(manager != null)
			manager.onResume();
		Log.d("manager","onresume");
	}

	@Override
	protected void onStop() {
		super.onStop();
		if(manager != null)
			manager.onStop();
		Log.d("manager","onpause");
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		if(manager != null)
			manager.onSaveInstanceState(outState);
		Log.d("manager","onSaveInstanceState");
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState){
		if(manager != null)
			manager.onRestoreInstanceState(savedInstanceState);
		super.onRestoreInstanceState(savedInstanceState);
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Dialog res = manager != null ? manager.onCreateDialog(id) : null;
		if(res == null)
			res = super.onCreateDialog(id);
		return res;
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		super.onPrepareDialog(id, dialog);

		if(manager != null)
			manager.onPrepareDialog(id, dialog);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(manager != null && false == manager.onKeyDown(keyCode, event))
			return super.onKeyDown(keyCode, event);

		return true;
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		if(manager != null && false == manager.onKeyUp(keyCode, event))
			return super.onKeyUp(keyCode, event);

		return true;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		return manager != null && manager.onCreateOptionsMenu(menu);
	}

	@Override
	public void onOptionsMenuClosed(Menu menu) {
		super.onOptionsMenuClosed(menu);

		if(manager != null)
			manager.onOptionsMenuClosed(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(manager != null && false == manager.onOptionsItemSelected(item))
			return super.onOptionsItemSelected(item);
		return true;
	}

}
